package com.chenyilei.demo.common.exception;

import com.chenyilei.demo.common.response.AjaxResult;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 统一异常处理
 *
 * @author chenyilei
 * @date 2019/03/14- 22:13
 */
@ControllerAdvice
@ResponseBody
public class ExceptionCatch {

    @ExceptionHandler(value = {SelfException.class})
    public Object myCatch(SelfException e){
        e.printStackTrace();
        return AjaxResult.error(e.getMsg());
    }

    @ExceptionHandler(value = {Exception.class})
    public Object exceptionCatch(Exception e){
        e.printStackTrace();
        return AjaxResult.error(e.getMessage());
    }
}
